﻿using System.Collections.Generic;
using System.IO;

namespace Framework
{
    public enum AssetType
    {
        AssetBundle, Texture, Text, Prefab, Material, Bytes, AudioClip, VideoClip, Asset, InputAction
    }

    public static class AssetTypeUtil
    {
        private static readonly Dictionary<string, AssetType> _ExtensionToAssetTypeMap = new Dictionary<string, AssetType>()
        {
            {".ab", AssetType.AssetBundle},
            {".jpg", AssetType.Texture},
            {".jpeg", AssetType.Texture},
            {".png", AssetType.Texture},
            {".txt", AssetType.Text},
            {".unity", AssetType.Prefab},
            {".prefab", AssetType.Prefab},
            {".mat", AssetType.Material},
            {".bytes", AssetType.Bytes},
            {".pfx", AssetType.Bytes},
            {".json", AssetType.Text},
            {".asset", AssetType.Asset},
            {".mp3", AssetType.AudioClip},
            {".wav", AssetType.AudioClip},
            {".mp4", AssetType.VideoClip},
            {".avi", AssetType.VideoClip},
            {".inputactions", AssetType.InputAction}
        };
        
        public static AssetType GetAssetType(string path)
        {
            AssetType assetType;
            string extension = Path.GetExtension(path);
            if (!_ExtensionToAssetTypeMap.TryGetValue(extension, out assetType))
            {
                assetType = AssetType.Text;
            }
            return assetType;
        }
    }
}